package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HaDrugPurchaseMapper;
import com.ruoyi.system.domain.HaDrugPurchase;
import com.ruoyi.system.service.IHaDrugPurchaseService;

/**
 * 采购单Service业务层处理
 * 
 * @author 鲍小伟
 * @date 2025-11-25
 */
@Service
public class HaDrugPurchaseServiceImpl implements IHaDrugPurchaseService 
{
    @Autowired
    private HaDrugPurchaseMapper haDrugPurchaseMapper;

    /**
     * 查询采购单
     * 
     * @param purchaseid 采购单主键
     * @return 采购单
     */
    @Override
    public HaDrugPurchase selectHaDrugPurchaseByPurchaseid(Long purchaseid)
    {
        return haDrugPurchaseMapper.selectHaDrugPurchaseByPurchaseid(purchaseid);
    }

    /**
     * 查询采购单列表
     * 
     * @param haDrugPurchase 采购单
     * @return 采购单
     */
    @Override
    public List<HaDrugPurchase> selectHaDrugPurchaseList(HaDrugPurchase haDrugPurchase)
    {
        return haDrugPurchaseMapper.selectHaDrugPurchaseList(haDrugPurchase);
    }

    /**
     * 新增采购单
     * 
     * @param haDrugPurchase 采购单
     * @return 结果
     */
    @Override
//    public HaDrugPurchase insertHaDrugPurchase(HaDrugPurchase haDrugPurchase)
//    {
//        haDrugPurchase.setCreateTime(DateUtils.getNowDate());
//       return haDrugPurchaseMapper.insertHaDrugPurchase(haDrugPurchase);
//    }
    public HaDrugPurchase insertHaDrugPurchase(HaDrugPurchase haDrugPurchase) {
        haDrugPurchase.setCreateTime(DateUtils.getNowDate());
        haDrugPurchaseMapper.insertHaDrugPurchase(haDrugPurchase);   // 插入后主键已回填
        return haDrugPurchase;   // 返回整个实体（含 purchaseid）
    }

    /**
     * 修改采购单
     * 
     * @param haDrugPurchase 采购单
     * @return 结果
     */
    @Override
    public int updateHaDrugPurchase(HaDrugPurchase haDrugPurchase)
    {
        haDrugPurchase.setUpdateTime(DateUtils.getNowDate());
        return haDrugPurchaseMapper.updateHaDrugPurchase(haDrugPurchase);
    }

    /**
     * 批量删除采购单
     * 
     * @param purchaseids 需要删除的采购单主键
     * @return 结果
     */
    @Override
    public int deleteHaDrugPurchaseByPurchaseids(Long[] purchaseids)
    {
        return haDrugPurchaseMapper.deleteHaDrugPurchaseByPurchaseids(purchaseids);
    }

    /**
     * 删除采购单信息
     * 
     * @param purchaseid 采购单主键
     * @return 结果
     */
    @Override
    public int deleteHaDrugPurchaseByPurchaseid(Long purchaseid)
    {
        return haDrugPurchaseMapper.deleteHaDrugPurchaseByPurchaseid(purchaseid);
    }
}
